<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="日期">
        <el-date-picker v-model="queryParams.create" type="date" value-format="yyyy-MM-dd" format="yyyy-MM-dd"
          class="small-date-picker" />
      </el-form-item>
      <el-form-item label="渠道名称" prop="channelName" class="single-line-label">
        <span class="label-spacing"></span>
        <el-select v-readonlyRemove v-model="selectedChannelNames" clearable placeholder="请选择渠道名称" filterable
          @change="updateChannelNames">
          <el-option v-for="(item, i) in extData.channelNameList || []" :key="i" :label="item.key"
            :value="item.key"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="small" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="small" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="countInfoList" :show-summary="true">
      <el-table-column label="渠道信息" align="center" prop="channelName" width="170"/>
      <el-table-column label="总数 " align="center" prop="total" />
      <el-table-column label="成功" align="center" prop="success" />
      <el-table-column label="失败 " align="center" prop="fail" />

    </el-table>
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
  </div>
</template>




<script>
import { listBaseInfo, baseInfoExtData, } from "@/api/channel/baseInfo";
import dayjs from "dayjs";
import { listRecordInfoResult } from "@/api/sms/countInfo";

export default {
  name: "CountInfo",
  computed: {
    isMobileScreen() {
      return window.innerWidth <= 768;
    }
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 渠道统计信息表格数据
      countInfoList: [],
      allUvCount: [],
      baseInfoList: [],
      selectedChannelNames: "",
      uvInfoData: [],
      extData: {},
      channelData: {},
      UvCount: {},
      ownerInfoList: [],
      dialogVisible: false,
      uvInfoDialogVisible: false,
      selectedChannelCode: '',
      selectedChannelName: '',
      selectedDateInfo: '',
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      rules: {
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        create: dayjs().format('YYYY-MM-DD'),
      },
      form: {},
    };
  },
  created() {
    this.getList();
    const thirtySeconds = 60 * 1000; // 60秒的毫秒数
    // setInterval(() => {
    //   this.getList();
    // }, thirtySeconds);
    this.getOptions();
    this.initData();
  },
  methods: {
    updateChannelNames() {
      this.queryParams.channelName = this.selectedChannelNames
    },
    getOptions() {
      baseInfoExtData().then((response) => {
        this.extData = response.data;
      });
    },
    getList() {
      this.loading = true;
      listRecordInfoResult(this.queryParams).then(response => {
        this.countInfoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /**渠道下拉框搜索*/
    async initData() {
      const response = await listBaseInfo()
      this.baseInfoList = response.rows;
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        dateInfo: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams.create = '';
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
  }
};
</script>
<style>
.uv-table {
  width: 100%;
  border-collapse: collapse;
}

.uv-table th,
.uv-table td {
  border: 1px solid #e0e0e0;
  padding: 8px;
  text-align: center;
}

.uv-table th {
  background-color: #f5f5f5;
}

.table-card {
  padding: 20px;
}
</style>
